﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Transactions;
using SubSonic;
using Adex;
using System.Configuration;
using System.Data;

namespace MediaMonitor.Users
{
    public partial class master : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //hdnComentID.Value = Request.Cookies["User"]["UserID"].ToString();
        }
    
        protected void btnSearch_click(object sender, EventArgs e)
        {
            //TransactionOptions options = new TransactionOptions();
            //options.Timeout = new TimeSpan(0, 2, 0);
            //options.IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted;
            //TransactionScope ts = new TransactionScope(TransactionScopeOption.Suppress, options);
            //try
            //{
            //    SharedDbConnectionScope conn = new SharedDbConnectionScope(ConfigurationManager.ConnectionStrings["DBAdex"].ToString());
            //    try
            //    {
            try
            {
                TblConfiguración prLog = new TblConfiguración();
                prLog.UserID = Convert.ToInt32(Request.Cookies["User"]["UserID"]);
                prLog.DateX = DateTime.Now;

                if (chkDesign1.Checked)
                {
                    prLog.Design = 1;
                }

                else if (chkDesign2.Checked)
                {
                    prLog.Design = 2;
                }

                else if (chkDesign3.Checked)
                {
                    prLog.Design = 3;
                }
                else
                    prLog.Design = 0;
                if (chkLast.Checked)
                    prLog.Page = "last";
                else if (chkPending.Checked)
                    prLog.Page = "pending";
                else if (chkToday.Checked)
                    prLog.Page = "today";
                else if (chkSearch.Checked)
                    prLog.Page = "search";
                else
                    prLog.Page = "";
                //prLog.Save();

                //ts.Complete();
                if (prLog.Design == 0)
                {
                    string script = "alert(\"Please select atleast one design\");";
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "ServerControlScript", script, true);
                    return;
                }
                else
                {
                    int str = Convert.ToInt32(SPs.ConfiguraciónInsert(prLog.UserID, prLog.DateX, prLog.Design.ToString(), prLog.Page).ExecuteScalar());
                }


            }
            catch (Exception exception)
            {
                // ex2 = exception;
                // ts.Dispose();
                //   conn.Dispose();
            }
            //}
            //    finally
            //    {

            //        ((IDisposable)conn).Dispose();

            //    }
            //}
            //finally
            //{

            //    ((IDisposable)ts).Dispose();

            //}
          
        }
        protected void lnkConfiguración_Click(object sender, EventArgs e)
        {
            DataTable dt = SPs.Configuración(Convert.ToInt32(Request.Cookies["User"]["UserID"].ToString())).GetDataSet().Tables[0];
            if (dt.Rows.Count > 0)
            {

                switch (dt.Rows[0]["Design"].ToString())
                {
                    case "1":
                        chkDesign1.Checked = true;
                        chkDesign2.Checked = false;
                        chkDesign3.Checked = false;
                        break;
                    case "2":
                        chkDesign1.Checked = false;
                        chkDesign2.Checked = true;
                        chkDesign3.Checked = false;
                        break;
                    case "3":
                        chkDesign1.Checked = false;
                        chkDesign2.Checked = false;
                        chkDesign3.Checked = true;
                        break;
                }
                switch (dt.Rows[0]["Page"].ToString())
                {
                    case "last":
                        chkLast.Checked = true;
                        chkPending.Checked = false;
                        chkToday.Checked = false;
                        chkSearch.Checked = false;
                        break;
                    case "pending":
                        chkLast.Checked = false;
                        chkPending.Checked = true;
                        chkToday.Checked = false;
                        chkSearch.Checked = false;
                        break;
                    case "today":
                        chkLast.Checked = false;
                        chkPending.Checked = false;
                        chkToday.Checked = true;
                        chkSearch.Checked = false;
                        break;
                    case "search":
                        chkLast.Checked = false;
                        chkPending.Checked = false;
                        chkToday.Checked = false;
                        chkSearch.Checked = true;
                        break;
                }
            }
            ModalPopupExtender2.Show();
        }
        protected void btnCancelPopup_Click(object sender, EventArgs e)
        {
            chkSearch.Checked = false;
            chkPending.Checked = false;
            chkLast.Checked = false;
            chkDesign3.Checked = false;
            chkDesign2.Checked = false;
            chkDesign1.Checked = false;
            chkToday.Checked = false;
            ModalPopupExtender2.Hide();
        }
    }
}